package com.oocl.multiPointDataTransmission;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.RandomAccessFile;

public class RWThread extends Thread{
	private int order;
	private String read;
	private String write;
	
	public RWThread(int order, String read,String write) {
		super();
		this.order = order;
		this.read = read;
		this.write = write;
		
	}

	@Override
	public void run() {
		try {
			RandomAccessFile raf1 = new RandomAccessFile(read, "rw");
			RandomAccessFile raf2 = new RandomAccessFile(write, "rw");
			long length=raf1.length();
			int quo=(int) length/4;
			int mod=(int) length%4;
			byte[] b = new byte[quo+mod];
			raf1.seek(order*(quo));
			raf2.seek(order*(quo));
			if(order!=3){
				raf1.read(b, 0, quo);
				raf2.write(b, 0, quo);
			}
			else{
				raf1.read(b, 0, quo+mod);
				raf2.write(b, 0, quo+mod);
			}
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
}
